//
//  AppDelegate.swift
//  customNavigationBarBackButton
//
//  Created by 李煜 on 2024/1/18.
//

import UIKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.backgroundColor = .white
        window?.rootViewController = CustomNavigationController(rootViewController: AViewController())
        window?.makeKeyAndVisible()



        //全局设置navigationbar backbutton
        let backImage = UIImage(named: "backMask")
        UINavigationBar.appearance().backIndicatorImage = backImage
        UINavigationBar.appearance().backIndicatorTransitionMaskImage = backImage

        return true
    }
}

extension UIViewController {
    func screen() -> UIScreen? {
        var parent = self.parent
        var lastParent = parent
        while parent != nil {
            lastParent = parent
            parent = parent?.parent
        }
        if #available(iOS 13.0, *) {
            return lastParent?.view.window?.windowScene?.screen
        } else {
            return nil
        }
    }
}
